package com.aidex.biz.rong360;

import com.aidex.biz.domain.Customer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args){
        boolean isTest = false;
        // 融360分配的appid, 上线时替换
        String appId = "5000669";
        // 融360分配的密钥, 注意不能删除回车和空格, 上线时替换
        String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALXWUSG+Avgiigd7" + "nxhH+89Djsn4jp8cgqSaRAFQ8Ahe+KrQWf78GLup7Uz+pgjyE314psmeRI7aHfIJ" + "imyCHBfxOkY1u1VnmpFs3me9jvYEIi1OxFMQDwkxyNA9aFvQtjQpQlThbkpnNer4" + "21EOv7QE60RTXZc//417CF6nlLeTAgMBAAECgYB/fSTjEHLKgITgHDd+cbHGLqql" + "RsTQH9AlEhfOCG5SoCuer3f5w8yfftNm4T+OFBPAK+Bcib+tnJXURgYsb8i7fgCP" + "H9+LHUsCDv8KVirw7m04bLFjEBOJWhK2YrJNF9O6HpRBVlYzoPEy3QQe2JZcgTzo" + "7nD7UvNqG+3vfy/JMQJBANzjgLowzlIXFdCfb0yFvRtbgVDdYOQAo38lMqkLrxw6" + "yTuIMAwu8fpd6VoxOcKoFjzFNg+G2ziQDIe3A3NqNosCQQDSvbafCzzztKjbCPh9" + "k2AoX2gpGpD5/nGn/Ht4HHiW55Hkq+jQjDmrlvvRmpB1wQUHDvvPgjIJgQaBid1S" + "sKwZAkBa+1IgXs38vgl8Ps9nI4b657viBO1NvH2bd0TgoDFmXUhZvwSbYBLHXzso" + "rTHvXbCbI1fbGV7ec2bV16oSNeN1AkEAqe25zQL10hlRstTH8hIdDlDoH4TBdCO8" + "p9UKBi8G+b+eP4JzB36angbv5PK6G4lZsXheidOU317/zQJKyXuWOQJBAJEUH4/q" + "cLb8M31LpLQF48CZqso7Ti3nWEfIWHHUXy1OszAVkuJkt5XoO412LUdhwiw83LrK" + "tNBJ6U/DOOtWmbM=";



//                privateKey="MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANJLMZrAyEBQyaur/SYia3qoT8Rpl0F9fM" +
//                "+IoT6LDeVDGDwIJV44Z8uWkqPmA2zKM/5FzarnO3KKngwJu6yYvCcyYOb1cHkbEej6QoT9LtkdpxnokiIR2bGfEpelRPZ563FmEX4fmmM/Xyfpbs2nd1+20hz77MJe95BFAEsQPkYpAgMBAAECgYEAkjBRqInx67v9pkjmr7bnzpno8dqRmqZYuJD7vtW98C2nUDw9dfVyOnZPNH72zI74fAAcjH04t1SjsCyn+cEnsjiCyyBNQOAfjO7jUxkEcgDRy6P19LexodKTaO3dNooV/33+klOIM2N2NQDKNXFRPGSkTDo3OS7WtM0MK/MnYx0CQQD5emyM9c5q+ABCU1mJ2Z9FGEBDUwDdy6TGYsOd7rHDcJwa2nXr3aXFA9T53Dd8NfyEa4iMu+MyW1x8puBVaVIDAkEA18qJVmaClRUNyP97ZZ/6ABhUbfZxaBMNy33tixwB5+KrsKxAATI8V4x7lZZcf1Aq1R62Yclu8aICQeJ6SviFYwJAKFjTS2zJiGU5bYCbX37xkjQc2IaJAlXX/Tml11nuJ+SDaphgL9g14gn/nLUvyAfXIfdeKxyL3u4FpCc86rNQzwJAGjq2Ithm+vQKLupO93VQj/5lFNClzD60qI1v+D65RJRaxijJxttyVjnvM6mJKLh33FvVU2GGqLxGhfefYcl/fQJBAJnWyrlGwNXO3jGgMrJ486K9pwBg/Z4gXjN8TLefgjizwctdqFm2qaJDe5run7iZpM6ePpK/68IiGjV2H41pcUg=";
        //融360分配的总账号ID, 联调时替换
        String uid = "838627";

        Rong360Service service = new Rong360Service(appId, privateKey, isTest);
        // 获取订单接口
        Map<String, String> params = new HashMap<String, String>();
        params.put("uid", uid);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
        Calendar calendarBegin = Calendar.getInstance();
        calendarBegin.add(Calendar.MINUTE, -2);
        params.put("begin_time", simpleDateFormat.format(calendarBegin.getTime()));
        // 将当前时间减去两分钟
        Calendar calendarEnd = Calendar.getInstance();
        params.put("end_time", simpleDateFormat.format(calendarEnd.getTime()));
        System.out.println(service.getorderlist(params));
        JSONObject jsonObjectRsp=JSONObject.parseObject(service.getorderlist(params));
        if("200".equals(jsonObjectRsp.getString("error"))){
            JSONObject orderListRsp=jsonObjectRsp.getJSONObject("bd_api_common_order_getorderlist_response");
            JSONArray cusList=orderListRsp.getJSONArray("data");
            for(int i=0;i<cusList.size();i++){
                System.out.println(cusList.getJSONObject(i).getString("city"));
//                Customer customer=new Customer();
//                customer.setId(cusList.getJSONObject(i).getString("id"));
//                customer.setIsNewRecord();
//                customer.setCityName(cusList.getJSONObject(i).getString("city"));
//                customer.setCusName(cusList.getJSONObject(i).getString("user_name"));
//                customer.setPhone(cusList.getJSONObject(i).getString("user_mobile"));
//                customer.setAmount(cusList.getJSONObject(i).getString("application_limit"));
//                customer.setRemark(cusList.getJSONObject(i).getString("product")+"/"+cusList.getJSONObject(i).getString("qsearch"));
            }
        }

        // 获取订单反馈接口
//        Map<String, String> feedbackParams = new HashMap<String, String>();
//        feedbackParams.put("order_id", "1");
//        feedbackParams.put("quality", "5星");
//        feedbackParams.put("remark", "有房 有车优质");
//        System.out.println(service.feedback(feedbackParams));

    }
}
